package com.hookgetaway.utils;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;

/* compiled from: Reflect.java */
/* loaded from: classes3.dex */
public class us1 {
    public final Object a;
    public final boolean b = true;

    /* compiled from: Reflect.java */
    /* loaded from: classes3.dex */
    public static class a {
    }

    public us1(Class<?> cls) {
        this.a = cls;
    }

    public static <T extends AccessibleObject> T a(T t) {
        if (t == null) {
            return null;
        }
        if (t instanceof Member) {
            Member member = (Member) t;
            if (Modifier.isPublic(member.getModifiers()) && Modifier.isPublic(member.getDeclaringClass().getModifiers())) {
                return t;
            }
        }
        if (!t.isAccessible()) {
            t.setAccessible(true);
        }
        return t;
    }

    public static Class<?> f(String str) throws vs1 {
        try {
            return Class.forName(str);
        } catch (Exception e) {
            throw new vs1(e);
        }
    }

    public static us1 j(Class<?> cls) {
        return new us1(cls);
    }

    public static us1 k(Object obj) {
        return new us1(obj);
    }

    public static us1 l(String str) throws vs1 {
        return j(f(str));
    }

    public static us1 m(Method method, Object obj, Object... objArr) throws vs1, InvocationTargetException, IllegalAccessException {
        return n(true, method, obj, objArr);
    }

    public static us1 n(boolean z, Method method, Object obj, Object... objArr) throws vs1, InvocationTargetException, IllegalAccessException {
        if (z) {
            try {
                a(method);
            } catch (Exception e) {
                throw new vs1(e);
            }
        }
        if (method.getReturnType() == Void.TYPE) {
            method.invoke(obj, objArr);
            return k(obj);
        }
        return k(method.invoke(obj, objArr));
    }

    public static Class<?>[] q(Object... objArr) {
        if (objArr == null) {
            return new Class[0];
        }
        Class<?>[] clsArr = new Class[objArr.length];
        for (int i = 0; i < objArr.length; i++) {
            Object obj = objArr[i];
            clsArr[i] = obj == null ? a.class : obj.getClass();
        }
        return clsArr;
    }

    public static Class<?> r(Class<?> cls) {
        if (cls == null) {
            return null;
        }
        if (!cls.isPrimitive()) {
            return cls;
        }
        if (Boolean.TYPE == cls) {
            return Boolean.class;
        }
        if (Integer.TYPE == cls) {
            return Integer.class;
        }
        if (Long.TYPE == cls) {
            return Long.class;
        }
        if (Short.TYPE == cls) {
            return Short.class;
        }
        if (Byte.TYPE == cls) {
            return Byte.class;
        }
        if (Double.TYPE == cls) {
            return Double.class;
        }
        if (Float.TYPE == cls) {
            return Float.class;
        }
        if (Character.TYPE == cls) {
            return Character.class;
        }
        return Void.TYPE == cls ? Void.class : cls;
    }

    public us1 b(String str, Object... objArr) throws vs1 {
        Class<?>[] q = q(objArr);
        try {
            try {
                return m(c(str, q), this.a, objArr);
            } catch (NoSuchMethodException unused) {
                return m(o(str, q), this.a, objArr);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            throw new vs1(e);
        }
    }

    public final Method c(String str, Class<?>[] clsArr) throws NoSuchMethodException {
        Class<?> p = p();
        try {
            return p.getMethod(str, clsArr);
        } catch (NoSuchMethodException unused) {
            do {
                try {
                    return p.getDeclaredMethod(str, clsArr);
                } catch (NoSuchMethodException unused2) {
                    p = p.getSuperclass();
                }
            } while (p != null);
            throw new NoSuchMethodException();
        }
    }

    public us1 d(String str) throws vs1 {
        try {
            return k(e(str).get(this.a));
        } catch (Exception e) {
            throw new vs1(e);
        }
    }

    public Field e(String str) throws vs1 {
        Class<?> p = p();
        try {
            return p.getField(str);
        } catch (NoSuchFieldException e) {
            do {
                try {
                    return (Field) a(p.getDeclaredField(str));
                } catch (NoSuchFieldException unused) {
                    p = p.getSuperclass();
                }
            } while (p != null);
            throw new vs1(e);
        }
    }

    public boolean equals(Object obj) {
        if (obj instanceof us1) {
            return this.a.equals(((us1) obj).g());
        }
        return false;
    }

    public <T> T g() {
        return (T) this.a;
    }

    public final boolean h(Method method, String str, Class<?>[] clsArr) {
        return method.getName().equals(str) && i(method.getParameterTypes(), clsArr);
    }

    public int hashCode() {
        return this.a.hashCode();
    }

    public final boolean i(Class<?>[] clsArr, Class<?>[] clsArr2) {
        if (clsArr.length != clsArr2.length) {
            return false;
        }
        for (int i = 0; i < clsArr2.length; i++) {
            if (clsArr2[i] != a.class && !r(clsArr[i]).isAssignableFrom(r(clsArr2[i]))) {
                return false;
            }
        }
        return true;
    }

    public final Method o(String str, Class<?>[] clsArr) throws NoSuchMethodException {
        Class<?> p = p();
        for (Method method : p.getMethods()) {
            if (h(method, str, clsArr)) {
                return method;
            }
        }
        do {
            for (Method method2 : p.getDeclaredMethods()) {
                if (h(method2, str, clsArr)) {
                    return method2;
                }
            }
            p = p.getSuperclass();
        } while (p != null);
        throw new NoSuchMethodException("No similar method " + str + " with params " + Arrays.toString(clsArr) + " could be found on type " + p() + ".");
    }

    public Class<?> p() {
        if (this.b) {
            return (Class) this.a;
        }
        return this.a.getClass();
    }

    public String toString() {
        return this.a.toString();
    }

    public us1(Object obj) {
        this.a = obj;
    }
}